import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileUtil;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;

import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.hadoop.mapreduce.Reducer;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.File;
import java.io.IOException;

public class DataNoHeavy {
    public static class DataMap extends Mapper<LongWritable, Text, Text, Text> {
        @Override
        protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
            Text line = value;
            context.write(line, new Text(","));
        }
    }

    private static class DataReduce extends Reducer<Text, Text, Text, Text> {
        @Override
        protected void reduce(Text key, Iterable<Text> values, Context context) throws IOException, InterruptedException {
            context.write(key, new Text(""));
        }
    }

    public static void main(String[] args) {
        try {
            Configuration configuration = new Configuration();

            Job job = Job.getInstance(configuration);
            job.setJarByClass(DataNoHeavy.class);

            job.setMapperClass(DataMap.class);
            job.setReducerClass(DataReduce.class);

            job.setOutputKeyClass(Text.class);
            job.setMapOutputValueClass(Text.class);

            File file = new File("d:/file/output");
            if (file.exists()){
                FileUtil.fullyDelete(file);
            }
            FileInputFormat.addInputPath(job,new Path("d:/file/input"));
            FileOutputFormat.setOutputPath(job,new Path("d:/file/output"));

            job.setNumReduceTasks(1);
            System.exit(job.waitForCompletion(true)?0:1);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}